#include "AnimationComponent.h"
#include "GameObject.h"
#include "VisualComponent.h"

AnimationComponent::AnimationComponent(){ m_animationManager = new vn::AnimationManager; }

AnimationComponent::AnimationComponent(const std::string& p_filepath)
{
	m_animationManager = new vn::AnimationManager;
	m_animationManager->loadAnimations(p_filepath);
}

AnimationComponent::AnimationComponent(const std::string& p_filepath, const std::string& p_animationID)
{
	m_animationManager = new vn::AnimationManager;
	m_animationManager->loadAnimations(p_filepath);
	m_animationManager->setAnimation(p_animationID);
}


AnimationComponent::~AnimationComponent()
{
	delete m_animationManager;
	m_animationManager = nullptr;
}

void AnimationComponent::init()
{
	IComponent* visualComponent = getOwner()->getComponent("VisualComponent");
	VisualComponent* visual = static_cast<VisualComponent*>(visualComponent);
	m_animationManager->setSprite(visual->getSprite());
}

void AnimationComponent::update(const GameTime& p_gameTime)
{
	m_animationManager->update(p_gameTime);
}

void AnimationComponent::loadAnimations(const std::string& p_filepath)
{
	m_animationManager->loadAnimations(p_filepath);
}

void AnimationComponent::setAnimation(const std::string& p_animID)
{
	m_animationManager->setAnimation(p_animID);
}